{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b83258f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(569, 30)\n",
      "[[1.799e+01 1.038e+01 1.228e+02 ... 2.654e-01 4.601e-01 1.189e-01]\n",
      " [2.057e+01 1.777e+01 1.329e+02 ... 1.860e-01 2.750e-01 8.902e-02]\n",
      " [1.969e+01 2.125e+01 1.300e+02 ... 2.430e-01 3.613e-01 8.758e-02]\n",
      " ...\n",
      " [1.660e+01 2.808e+01 1.083e+02 ... 1.418e-01 2.218e-01 7.820e-02]\n",
      " [2.060e+01 2.933e+01 1.401e+02 ... 2.650e-01 4.087e-01 1.240e-01]\n",
      " [7.760e+00 2.454e+01 4.792e+01 ... 0.000e+00 2.871e-01 7.039e-02]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.datasets import load_iris, load_breast_cancer\n",
    "from sklearn.svm import SVC\n",
    "from sklearn.model_selection import train_test_split\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "dataset = load_breast_cancer()\n",
    "x, y = dataset.data, dataset.target\n",
    "print(x.shape)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f6acc30c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.09706398 -2.07333501  1.26993369 ...  2.29607613  2.75062224\n",
      "   1.93701461]\n",
      " [ 1.82982061 -0.35363241  1.68595471 ...  1.0870843  -0.24388967\n",
      "   0.28118999]\n",
      " [ 1.57988811  0.45618695  1.56650313 ...  1.95500035  1.152255\n",
      "   0.20139121]\n",
      " ...\n",
      " [ 0.70228425  2.0455738   0.67267578 ...  0.41406869 -1.10454895\n",
      "  -0.31840916]\n",
      " [ 1.83834103  2.33645719  1.98252415 ...  2.28998549  1.91908301\n",
      "   2.21963528]\n",
      " [-1.80840125  1.22179204 -1.81438851 ... -1.74506282 -0.04813821\n",
      "  -0.75120669]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.preprocessing import StandardScaler\n",
    "x = StandardScaler().fit_transform(x)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc6b084d",
   "metadata": {},
   "source": [
    "使用四种函数分别训练模型，并计算准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5ef4aa0a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "选择=linear 核函数时，预测准确率为: 0.9766081871345029\n",
      "选择=poly 核函数时，预测准确率为: 0.9649122807017544\n",
      "选择=rbf 核函数时，预测准确率为: 0.9707602339181286\n",
      "选择=sigmoid 核函数时，预测准确率为: 0.9532163742690059\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=420)\n",
    "kernels = ['linear', 'poly', 'rbf', 'sigmoid']\n",
    "for kernel in kernels:\n",
    "    model = SVC(kernel=kernel, gamma='auto', degree=1)\n",
    "    model.fit(x_train, y_train)\n",
    "    pred = model.predict(x_test)\n",
    "    ac = accuracy_score(y_test, pred)\n",
    "    print(f'选择={kernel} 核函数时，预测准确率为: {ac}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5aa4c0bf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最佳参数组合: {'coef0': np.float64(100.0), 'gamma': np.float64(0.0008858667904100832)}\n",
      "最佳模型得分: 0.9695906432748538\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import StratifiedShuffleSplit\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "\n",
    "gamma_range = np.logspace(-10, 1, 20)\n",
    "coef0_range = np.logspace(-5, 4, 10)\n",
    "param_grid = dict(gamma=gamma_range, coef0=coef0_range)\n",
    "cv = StratifiedShuffleSplit(n_splits=5, test_size=0.3, random_state=420)\n",
    "grid = GridSearchCV(SVC(kernel='poly', degree=2), param_grid=param_grid, cv=cv)\n",
    "grid.fit(x, y)\n",
    "print(f'最佳参数组合: {grid.best_params_}')\n",
    "print(f'最佳模型得分: {grid.best_score_}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "30768354",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiwAAAGdCAYAAAAxCSikAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjYsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvq6yFwwAAAAlwSFlzAAAPYQAAD2EBqD+naQAANUlJREFUeJzt3X14VPWd///XZJLMBEkmQkoSTAwRoQRSWUy4SWK0rRrEmy+2VeK2xKKhyg+rRKpXm0XbwlpT7MqFBRJLhU3pWomWZaW7eBNtl5sNisSEWugCLmgiToxByICBBJLz+yPM4JjbCUnOSfJ8XNe51px8zsn7DFd3XtfnfM772AzDMAQAAGBhQWYXAAAA0BUCCwAAsDwCCwAAsDwCCwAAsDwCCwAAsDwCCwAAsDwCCwAAsDwCCwAAsLxgswvoLS0tLfr4448VHh4um81mdjkAAKAbDMPQyZMnNXr0aAUFdTyPMmgCy8cff6z4+HizywAAAD1QXV2tuLi4Dn8/aAJLeHi4pNYLjoiIMLkaAADQHR6PR/Hx8b7v8Y4MmsDivQ0UERFBYAEAYIDpajkHi24BAIDlEVgAAIDlEVgAAIDlEVgAAIDlEVgAAIDlEVgAAIDlEVgAAIDlEVgAAIDlEVgAAIDlEVgAAIDlEVgAAIDlEVgAAIDlEVi6YBiGNuz6QOUfHje7FAAAhqxB87bmvvLn/63VT1/eJ0n64Je3mFwNAABDEzMsXThS97nZJQAAMOQRWLoQGsxHBACA2fg27kKonY8IAACz8W3chS/OsHx0vMHESgAAGLoILF0I+cIMyzXL/2JiJQAADF0Eli58eQ1LQ9M5kyoBAGDoIrB0wfaln/d/7DGlDgAAh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KSUnRjh07zC5pUCkoKNDUqVMVHh6uUaNG6fbbb9eBAwfMLmvQKygokM1mU15entmlDDpHjx7V3LlzNXLkSA0bNkz/8A//oPLycrPLGnTOnTunxx57TImJiQoLC9MVV1yhZcuWqaWlxezSBrTt27frtttu0+jRo2Wz2fQf//Effr83DEM///nPNXr0aIWFhenrX/+69u3b1y+1EVg6UVJSory8PC1ZskQVFRXKzMzUrFmzVFVVZXZpg8a2bdv0wAMP6K233lJpaanOnTunrKwsff7552aXNmi98847Wrt2ra666iqzSxl0jh8/royMDIWEhOiVV17R/v379fTTTysyMtLs0gad5cuX69lnn9Xq1av197//XU899ZR+9atfadWqVWaXNqB9/vnnmjx5slavXt3u75966imtWLFCq1ev1jvvvKOYmBjdeOONvvf59SkDHZo2bZqxYMECv30TJkwwfvKTn5hU0eBXW1trSDK2bdtmdimD0smTJ41x48YZpaWlxnXXXWcsWrTI7JIGlR//+MfGNddcY3YZQ8Itt9xi3HvvvX77vv3tbxtz5841qaLBR5KxefNm388tLS1GTEyM8ctf/tK378yZM4bL5TKeffbZPq+HGZYONDU1qby8XFlZWX77s7KyVFZWZlJVg199fb0kacSIESZXMjg98MADuuWWW3TDDTeYXcqgtGXLFqWmpurOO+/UqFGjNGXKFP32t781u6xB6ZprrtGbb76pgwcPSpL27t2rnTt36uabbza5ssHryJEjqqmp8ftedDgcuu666/rle3HQvPywt9XV1am5uVnR0dF++6Ojo1VTU2NSVYObYRhavHixrrnmGiUnJ5tdzqCzceNGvfvuu3rnnXfMLmXQOnz4sIqKirR48WL90z/9k3bv3q2HHnpIDodDd999t9nlDSo//vGPVV9frwkTJshut6u5uVm/+MUv9I//+I9mlzZoeb/72vte/PDDD/v87xNYumCz2fx+NgyjzT70jh/+8If661//qp07d5pdyqBTXV2tRYsW6fXXX5fT6TS7nEGrpaVFqampevLJJyVJU6ZM0b59+1RUVERg6WUlJSX6t3/7N/3hD3/QpEmTVFlZqby8PI0ePVrf//73zS5vUDPre5HA0oGoqCjZ7fY2sym1tbVt0iUu3oMPPqgtW7Zo+/btiouLM7ucQae8vFy1tbVKSUnx7Wtubtb27du1evVqNTY2ym63m1jh4BAbG6uJEyf67UtKStKmTZtMqmjwevTRR/WTn/xEd911lyTpa1/7mj788EMVFBQQWPpITEyMpNaZltjYWN/+/vpeZA1LB0JDQ5WSkqLS0lK//aWlpUpPTzepqsHHMAz98Ic/1L//+7/rz3/+sxITE80uaVC6/vrr9d5776mystK3paam6nvf+54qKysJK70kIyOjzWP5Bw8eVEJCgkkVDV4NDQ0KCvL/CrPb7TzW3IcSExMVExPj973Y1NSkbdu29cv3IjMsnVi8eLFycnKUmpqqtLQ0rV27VlVVVVqwYIHZpQ0aDzzwgP7whz/o5ZdfVnh4uG9Gy+VyKSwszOTqBo/w8PA264IuueQSjRw5kvVCvejhhx9Wenq6nnzySc2ZM0e7d+/W2rVrtXbtWrNLG3Ruu+02/eIXv9Dll1+uSZMmqaKiQitWrNC9995rdmkD2qlTp/T+++/7fj5y5IgqKys1YsQIXX755crLy9OTTz6pcePGady4cXryySc1bNgwffe73+374vr8OaQBbs2aNUZCQoIRGhpqXH311Txu28sktbv967/+q9mlDXo81tw3/vSnPxnJycmGw+EwJkyYYKxdu9bskgYlj8djLFq0yLj88ssNp9NpXHHFFcaSJUuMxsZGs0sb0P7yl7+0+/+Tv//97xuG0fpo889+9jMjJibGcDgcxrXXXmu89957/VKbzTAMo+9jEQAAQM+xhgUAAFgegQUAAFgegQUAAFgegQUAAFgegQUAAFgegQUAAFgegQUAAFgegQUAAFgegQUAAFgegQUAAFgegQUAAFgegQUAAFje/w+qM5wxOudrCgAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "参加gamma的最优值为: 0.012067926406393264\n",
      "最优值对应的准确率为: 0.9766081871345029\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "score = []\n",
    "gamma_range = np.logspace(-10, 1, 50)\n",
    "for i in gamma_range:\n",
    "    model = SVC(kernel='rbf', gamma=i)\n",
    "    model.fit(x_train, y_train)\n",
    "    pred = model.predict(x_test)\n",
    "    ac = accuracy_score(y_test, pred)\n",
    "    score.append(ac)\n",
    "\n",
    "plt.plot(gamma_range, score)\n",
    "plt.show()\n",
    "\n",
    "print(f'参加gamma的最优值为: {gamma_range[np.argmax(score)]}')\n",
    "print(f'最优值对应的准确率为: {max(score)}')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ml-course",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
